<?php
if (!defined('ROOT')) exit('SYTbHelper');
//设置相关
class setting_model extends base {
	static private $_instance=NULL;
	static public function getInstance () {
		if (!self::$_instance) self::$_instance=new self;
		return self::$_instance;
	}
	public function __construct () {
		parent::init();
		$_ENV['_now']='setting';
	}
	//基本设置
	public function onbasic () {
		if (isset($_POST['submit'])) {
			$all=array('cookie'=>htmlspecialchars(getgpc('cookie','P')));
			foreach ($all as $k=>$v) $this->setval($k,$v);
			$this->ShowTips('已保存','success');
		} else {
			$cookie=$this->get_cookie();
			include(TPL.'setting_basic.html');
		}
	}
	//Cron设置
	public function oncron () {
		if (isset($_POST['submit'])) {
			$cron=array();
			$cfgs=array('sign','reply','ban');
			$time=getgpc('time','P');
			$enable=getgpc('enable','P');
			foreach ($cfgs as $me) {
				if (isset($time[$me])) {
					$cron[$me]=array('enable'=>($enable[$me]==1?TRUE:FALSE),'time'=>$time[$me]);
					if ($cron[$me]['enable']) {
						if (strlen($time[$me])!==0 && (strlen($time[$me])!==4 || !preg_match('/^(\d+)$/',$time[$me]))) $this->DisplayError('时间格式不正确');
					}
				} else {
					$cron[$me]=array('enable'=>($enable[$me]==1?TRUE:FALSE));
				}
			}
			$this->db('set','cron',$cron);
			$this->ShowTips('已保存','success');
		} else {
			$cron=$this->db('get','cron');
			include(TPL.'setting_cron.html');
		}
	}
	//回贴设置
	public function onreply () {
		if (isset($_POST['submit'])) {
			$t=getgpc('time','P');
		} else {
			$cookie=$this->get_cookie();
			include(TPL.'setting_sign.html');
		}
	}
}
?>